//
//  PositioningHelper.h
//  etionMisc
//
//  Created by wangjian on 4/26/13.
//
//

#import <Foundation/Foundation.h>

#import <CoreLocation/CoreLocation.h>

typedef enum
{
    XLGPositioningErrorFail,
    XLGPositioningErrorSystemServiceDisable,
    XLGPositioningErrorAppServiceDisable,
    XLGPositioningErrorNetworkNotReachable,
    XLGPositioningErrorCancel
}XLGPositioningError;

typedef enum
{
    XLGRouteSearchTypeCar,
    XLGRouteSearchTypeBus,
    XLGRouteSearchTypeWalk,
    XLGRouteSearchTypeNum
} XLGRouteSearchType;

///此类表示地址结果的层次化信息
@interface XLGPositingAddressComponent : NSObject

/// 街道号码
@property (nonatomic, readonly) NSString* streetNumber;
/// 街道名称
@property (nonatomic, readonly) NSString* streetName;
/// 区县名称
@property (nonatomic, readonly) NSString* district;
/// 城市名称
@property (nonatomic, readonly) NSString* city;
/// 省份名称
@property (nonatomic, readonly) NSString* province;

@end

@protocol XLGPositingPlanNode
@property (nonatomic,readonly) NSString* cityName;
@property (nonatomic,readonly) NSString* name;
@property (nonatomic) CLLocationCoordinate2D pt;
@end

@protocol XLGPositingReverseGeoCodeResult
@property (nonatomic,readonly) NSString* address;
@property (nonatomic,readonly) CLLocationCoordinate2D location;
@property (nonatomic,readonly) XLGPositingAddressComponent *addressDetail;

@end

@class XLGPositioningHelper;
@protocol XLGPositioningHelperDelegate <NSObject>

@optional
- (void)positioningHelperUpdateCoord:(CLLocation *)location userInfo:(id)userInfo error:(NSError *)error;
- (void)positioningHelperUpdateAddr:(id<XLGPositingReverseGeoCodeResult>)addr userInfo:(id)userInfo error:(NSError *)error;

@end


@interface XLGPositioningHelper : NSObject 
{
}

+ (void)openService;
+ (void)closeService;

+ (BOOL)isNetworkReachable;

/**
 *  定位服务是否可用，systemLocationServiceVisible == NO || appLocationServiceVisible == NO  -> NO
 *  注意，若定位服务没有被激活，使用此方法会造成定位服务永远不能被开启，优先使用systemServiceVisible判断 
 *
 *  @return YES/NO
 */
+ (BOOL)locationServiceVisible;

/**
 *  系统是否打开定位服务
 *
 *  @return YES/NO
 */
+ (BOOL)systemServiceVisible;

/**
 *  当前应用是否允许定位
 *
 *  @return YES/NO
 */
+ (BOOL)appServiceVisible;

+ (void)getCoordWithReceiver:(id<XLGPositioningHelperDelegate>)receiver completion:(void (^)(BOOL finished, CLLocation *location, NSError *error))completion;
+ (void)getCoordWithReceiver:(id<XLGPositioningHelperDelegate>)receiver addr:(NSString *)addr city:(NSString *)city completion:(void (^)(BOOL finished, CLLocation *location, NSString *address, NSError *error))completion;
+ (void)getAddrWithReceiver:(id<XLGPositioningHelperDelegate>)receiver coordinate:(CLLocationCoordinate2D)coord completion:(void (^)(BOOL finished, id<XLGPositingReverseGeoCodeResult> addrInfo, NSError *error))completion;
+ (void)getRouteWithReceiver:(id<XLGPositioningHelperDelegate>)receiver startNode:(id<XLGPositingPlanNode>)startNode endNode:(id<XLGPositingPlanNode>)endNode type:(XLGRouteSearchType)type completion:(void (^)(BOOL finished, id result, NSError *error))completion;

+ (BOOL)cancelGetCoordWithReceiver:(id<XLGPositioningHelperDelegate>)receiver;
+ (BOOL)cancelGetCoordByAddrWithReceiver:(id<XLGPositioningHelperDelegate>)receiver;
+ (BOOL)cancelGetAddrWithReceiver:(id<XLGPositioningHelperDelegate>)receiver;
+ (BOOL)cancelGetRouteWithReceiver:(id<XLGPositioningHelperDelegate>)receiver;

+ (void)cancelReceiver:(id<XLGPositioningHelperDelegate>)recviver;

@end
